package com.example.config.baiduAi;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: tobed
 * @date: 2022/11/23
 * @time: 16:00
 */
@RestController
@RequestMapping("read")
public class PeopleTest {


    /**【语音播报方法】**/
    @GetMapping("read/{readText}")
    public static boolean speakingText(@PathVariable String readText){
        boolean isFinish = true;
        ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
        try {
            sap.setProperty("Volume",new Variant(100));              // 音量 0-100
            sap.setProperty("Rate",new Variant(-3));                 // 语音朗读速度 -10 到 +10
            Dispatch sapo = sap.getObject();                         // 获取执行对象
            Dispatch.call(sapo,"Speak",new Variant(readText));    	// 执行朗读
            sapo.safeRelease();                                     // 关闭执行对象
        }catch (Exception e){
            isFinish = false;
            e.printStackTrace();
        }finally {
            sap.safeRelease();                                      // 关闭执行对象
        }
        return isFinish;
    }

    public static void main(String[] args) {
        boolean isFinish = true;
        ActiveXComponent sap = new ActiveXComponent("Sapi.SpVoice");
        try {
            sap.setProperty("Volume",new Variant(100));              // 音量 0-100
            sap.setProperty("Rate",new Variant(10));                 // 语音朗读速度 -10 到 +10
            Dispatch sapo = sap.getObject();                         // 获取执行对象
            Dispatch.call(sapo,"Speak",new Variant("只因你太美 baby 只因你太美 baby\n" +
                    "\n" +
                    "只因你实在是太美 baby\n" +
                    "\n" +
                    "只因你太美 baby\n" +
                    "\n" +
                    "迎面走来的你让我如此蠢蠢欲动\n" +
                    "\n" +
                    "这种感觉我从未有\n" +
                    "\n" +
                    "Cause I got a crush on you who you\n" +
                    "\n" +
                    "你是我的我是你的谁\n" +
                    "\n" +
                    "再多一眼看一眼就会爆炸\n" +
                    "\n" +
                    "再近一点靠近点快被融化\n" +
                    "\n" +
                    "想要把你占为己有 baby bae\n" +
                    "\n" +
                    "不管走到哪里\n" +
                    "\n" +
                    "都会想起的人是你 you you\n" +
                    "\n" +
                    "我应该拿你怎样\n" +
                    "\n" +
                    "Uh 所有人都在看着你\n" +
                    "\n" +
                    "我的心总是不安\n" +
                    "\n" +
                    "Oh 我现在已病入膏肓\n" +
                    "\n" +
                    "Eh oh\n" +
                    "\n" +
                    "难道真的因你而疯狂吗\n" +
                    "\n" +
                    "我本来不是这种人\n" +
                    "\n" +
                    "因你变成奇怪的人\n" +
                    "\n" +
                    "第一次呀变成这样的我\n" +
                    "\n" +
                    "不管我怎么去否认\n" +
                    "\n" +
                    "只因你太美 baby 只因你太美 baby\n" +
                    "\n" +
                    "只因你实在是太美 baby\n" +
                    "\n" +
                    "只因你太美 baby\n" +
                    "\n" +
                    "Oh eh oh\n" +
                    "\n" +
                    "现在确认地告诉我\n" +
                    "\n" +
                    "Oh eh oh\n" +
                    "\n" +
                    "你到底属于谁\n" +
                    "\n" +
                    "Oh eh oh\n" +
                    "\n" +
                    "现在确认地告诉我\n" +
                    "\n" +
                    "Oh eh oh\n" +
                    "\n" +
                    "你到底属于谁\n" +
                    "\n" +
                    "就是现在告诉我\n" +
                    "\n" +
                    "跟着那节奏 缓缓 make wave\n" +
                    "\n" +
                    "甜蜜的奶油 it's your birthday cake\n" +
                    "\n" +
                    "男人们的 game call me 你恋人\n" +
                    "\n" +
                    "别被欺骗愉快的 I wanna play\n" +
                    "\n" +
                    "我的脑海每分每秒为你一人沉醉\n" +
                    "\n" +
                    "最迷人让我神魂颠倒是你身上香水\n" +
                    "\n" +
                    "Oh right baby I'm fall in love with you\n" +
                    "\n" +
                    "我的一切你都拿走\n" +
                    "\n" +
                    "只要有你就已足够\n" +
                    "\n" +
                    "我到底应该怎样\n" +
                    "\n" +
                    "Uh 我心里一直很不安\n" +
                    "\n" +
                    "其他男人们的视线\n" +
                    "\n" +
                    "Oh 全都只看着你的脸\n" +
                    "\n" +
                    "Eh oh\n" +
                    "\n" +
                    "难道真的因你而疯狂吗\n" +
                    "\n" +
                    "我本来不是这种人\n" +
                    "\n" +
                    "因你变成奇怪的人\n" +
                    "\n" +
                    "第一次呀变成这样的我\n" +
                    "\n" +
                    "不管我怎么去否认\n" +
                    "\n" +
                    "只因你太美 baby 只因你太美 baby\n" +
                    "\n" +
                    "只因你实在是太美 baby\n" +
                    "\n" +
                    "只因你太美 baby\n" +
                    "\n" +
                    "我愿意把我的全部都给你\n" +
                    "\n" +
                    "我每天在梦里都梦见你\n" +
                    "\n" +
                    "还有我闭着眼睛也能看到你\n" +
                    "\n" +
                    "现在开始我只准你看我\n" +
                    "\n" +
                    "I don't wanna wake up in dream\n" +
                    "\n" +
                    "我只想看你这是真心话\n" +
                    "\n" +
                    "只因你太美 baby 只因你太美 baby\n" +
                    "\n" +
                    "只因你实在是太美 baby\n" +
                    "\n" +
                    "只因你太美 baby\n" +
                    "\n" +
                    "Oh eh oh\n" +
                    "\n" +
                    "现在确认的告诉我\n" +
                    "\n" +
                    "Oh eh oh\n" +
                    "\n" +
                    "你到底属于谁\n" +
                    "\n" +
                    "Oh eh oh\n" +
                    "\n" +
                    "现在确认的告诉我\n" +
                    "\n" +
                    "Oh eh oh\n" +
                    "\n" +
                    "你到底属于谁就是现在告诉我"));    	// 执行朗读
            sapo.safeRelease();                                     // 关闭执行对象
        }catch (Exception e){
            isFinish = false;
            e.printStackTrace();
        }finally {
            sap.safeRelease();                                      // 关闭执行对象
        }
    }


}
